// https://leetcode.cn/problems/compare-version-numbers/
// Created by ade on 2022/8/24.
//
#include <iostream>
#include <string>
#include <regex>
#include <vector>
#include <sstream>

using namespace std;

class Solution {
public:
    int compareVersion(string version1, string version2) {
        vector<int> v1 = {};
        vector<int> v2 = {};
        stringstream s1(version1);
        stringstream s2(version2);
        string t1 = "";
        string t2 = "";
        while (getline(s1, t1, '.')) {
            v1.push_back(stoi(t1));
        }
        while (getline(s2, t2, '.')) {
            v2.push_back(stoi(t2));
        }
        int len1 = v1.size();
        int len2 = v2.size();
        if (len1 < len2) {
            int diff = len2 - len1;
            while (diff > 0) {
                v1.push_back(0);
                diff--;
            }
        }
        if (len1 > len2) {
            int diff = len1 - len2;
            while (diff > 0) {
                v2.push_back(0);
                diff--;
            }
        }
        int len = max(len1, len2);

        for (int i = 0; i < len; i++) {
            if (v1[i] == v2[i]) continue;
            if (v1[i] < v2[i]) return -1;
            if (v1[i] > v2[i]) return 1;
        }

        return 0;
    }

    // 官方解法
    int compareVersion(string version1, string version2) {
        int n = version1.length(), m = version2.length();
        int i = 0, j = 0;
        while (i < n || j < m) {
            int x = 0;
            for (; i < n && version1[i] != '.'; ++i) {
                x = x * 10 + (version1[i] - '0');
            }
            ++i; // 跳过点号
            int y = 0;
            for (; j < m && version2[j] != '.'; ++j) {
                y = y * 10 + (version2[j] - '0');
            }
            ++j; // 跳过点号
            if (x != y) {
                return x > y ? 1 : -1;
            }
        }
        return 0;
    }
};


int main() {
    Solution so;
//    string s1 = "7.5.2.4";
//    string s2 = "7.5.3";
    string s1 = "1.0";
    string s2 = "1.0.0";
    cout << so.compareVersion(s1, s2) << endl;
    return 0;
}